#include <iostream>
#include <vector>

using namespace std;
class MyCircularQueue
{
private:
    int front;
    int rear;
    int capacity;
    vector<int> elements;

public:
    MyCircularQueue(int k)
    {
        this->capacity = k + 1;
        this->elements = vector<int>(capacity);
        rear = front = 0;
    }

    bool enQueue(int value)
    {
        if (isFull())
        {
            return false;
        }
        elements[rear] = value;
        rear = (rear + 1) % capacity;
        return true;
    }

    bool deQueue()
    {
        if (isEmpty())
        {
            return false;
        }
        front = (front + 1) % capacity;
        return true;
    }

    int Front()
    {
        if (isEmpty())
        {
            return -1;
        }
        return elements[front];
    }

    int Rear()
    {
        if (isEmpty())
        {
            return -1;
        }
        return elements[(rear - 1 + capacity) % capacity];
    }

    bool isEmpty()
    {
        return rear == front;
    }

    bool isFull()
    {
        return (rear + 1) % capacity == front;
    }
};

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue* obj = new MyCircularQueue(k);
 * bool param_1 = obj->enQueue(value);
 * bool param_2 = obj->deQueue();
 * int param_3 = obj->Front();
 * int param_4 = obj->Rear();
 * bool param_5 = obj->isEmpty();
 * bool param_6 = obj->isFull();
 */
int main(int argc, char const *argv[])
{
    // 设置长度为 3
    MyCircularQueue circularQueue = MyCircularQueue(6);
    cout << "isEmpty: " << circularQueue.isEmpty() << endl;
    // 返回 true
    cout << circularQueue.enQueue(6) << endl;
    // 3
    cout << circularQueue.Rear() << endl;
    cout << circularQueue.Rear() << endl;
    cout << circularQueue.deQueue() << endl;
    // 返回 true
    cout << circularQueue.enQueue(5) << endl;
    cout << circularQueue.Rear() << endl;
    cout << "deQueue: " << circularQueue.deQueue() << endl;
    cout << "deQueue: " << circularQueue.deQueue() << endl;
    cout << "deQueue: " << circularQueue.deQueue() << endl;
    return 0;
}
